<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('users')) {
            Schema::create('users', function (Blueprint $table) {
                $table->id();
                $table->string('name');
                $table->string('nickname', 64);
                $table->integer('leader_id')->default(0)->comment('上级 ID');
                $table->string('mobile', 32)->unique();
                $table->string('avatar')->nullable()->comment('用户头像');
                $table->string('openid', 32)->nullable()->comment('用户微信 OPENID, 为空则为未绑定微信');
                $table->string('unionid', 32)->nullable()->comment('用户微信 UNIONID');
                $table->enum('sex', ['F', 'M', 'U'])->default('U')->comment('性别: F = 女, M = 男, U = 男女通杀');
                $table->enum('status', ['normal', 'approve'])->default('approve')->comment('用户状态: approve = 待审核, normal = 正常');
                $table->timestamp('disabled_time')->nullable()->comment('禁用时间');
                $table->integer('sign_num')->default(0)->comment('总登录次数');
                $table->integer('order')->default(0)->comment('排序');
                $table->timestamps();
            });
            DB::statement("ALTER TABLE `users` comment '用户表'");
        }
        
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
